﻿package mortal.game.view.copy
{
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class CopyInfoPanelBase extends View
    {
        protected var _bodySprite:GSprite;
        private var _spFunc:GSprite;
        private var _dragRect:Rectangle;
        protected var _moveBtn:GLoadedButton;
        private var _spExpandContainer:ToolTipSprite;
        private var _btnExpandBg:GLoadedButton;
        private var _btnExpand:GLoadedButton;
        protected var _btnUnExpand:GLoadedButton;
        private var _bmpCopyLabel:GImageBitmap;
        private var _tween:TimelineLite;
        private var _isExpanding:Boolean = true;
        private var _myWidth:int = 250;
        private var _myHeight:int = 380;
        protected var _paddingLeft:int = 6;
        protected var _labelName:String = "";

        public function CopyInfoPanelBase(param1:String = "", param2:int = 250, param3:int = 380, param4:int = 6)
        {
            this._myWidth = param2;
            this._myHeight = param3;
            this._paddingLeft = param4;
            if (param1 != null)
            {
                this._labelName = param1;
            }
            this.layer = LayerManager.uiLayer;
            return;
        }// end function

        public function get isExpanding() : Boolean
        {
            return this._isExpanding;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            CopyInfo_TaskTrackConnector.registerCopy(this);
            super.show(param1, param2);
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            CopyInfo_TaskTrackConnector.unregisterCopy();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._isExpanding = true;
            this._dragRect = new Rectangle();
            this._dragRect.x = 0;
            this._dragRect.y = 0;
            this._dragRect.width = SceneRange.display.width - 30;
            this._dragRect.height = SceneRange.display.height - 30;
            this._spFunc = UICompomentPool.getUICompoment(GSprite) as GSprite;
            super.addChild(this._spFunc);
            this._bodySprite = UICompomentPool.getUICompoment(GSprite) as GSprite;
            this._spFunc.addChild(this._bodySprite);
            this._moveBtn = UIFactory.gLoadedButton(ImagesConst.TaskTrackMove_upSkin, 4, 12, 20, 20, this._spFunc);
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(20143), "#FFFFFF");
            this._moveBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseHandler);
            this._moveBtn.x = this._paddingLeft;
            this._btnUnExpand = UIFactory.gLoadedButton(ImagesConst.taskTrackRight_upSkin, this._myWidth - 26, 12, 20, 20, this._spFunc);
            this._btnUnExpand.x = this._myWidth - this._btnUnExpand.width - this._paddingLeft;
            this._spExpandContainer = UICompomentPool.getUICompoment(ToolTipSprite) as ToolTipSprite;
            this._spExpandContainer.x = this._myWidth - 34;
            this._spExpandContainer.y = 7;
            this._spExpandContainer.mouseChildren = true;
            this._spExpandContainer.mouseEnabled = true;
            this._btnExpandBg = UIFactory.gLoadedButton(ImagesConst.taskTrack_upSkin, 0, 0, 35, 101, this._spExpandContainer);
            this._btnExpand = UIFactory.gLoadedButton(ImagesConst.taskTrackLeft_upSkin, 11, 6, 20, 20, this._spExpandContainer);
            this._bmpCopyLabel = UIFactory.gImageBitmap(this._labelName, 13, 29, this._spExpandContainer);
            this._btnUnExpand.configEventListener(MouseEvent.CLICK, this.unExpandHandler);
            this._btnUnExpand.toolTipData = Language.getString(20996);
            this._spExpandContainer.configEventListener(MouseEvent.CLICK, this.expandHandler);
            this._spExpandContainer.toolTipData = Language.getString(20997);
            return;
        }// end function

        override public function get width() : Number
        {
            return this._myWidth;
        }// end function

        override public function get height() : Number
        {
            return this._myHeight;
        }// end function

        public function unExpandHandler(param1 = null) : void
        {
            if (this._tween != null && this._tween.active)
            {
                this._tween.kill();
                this._tween = null;
            }
            this._tween = new TimelineLite();
            this._tween.append(TweenLite.to(this._spFunc, 0.2, {x:430}));
            super.addChild(this._spExpandContainer);
            this._isExpanding = false;
            CopyInfo_TaskTrackConnector.updateLaout(true);
            return;
        }// end function

        public function expandHandler(param1 = null) : void
        {
            if (this._tween != null && this._tween.active)
            {
                this._tween.kill();
                this._tween = null;
            }
            this._tween = new TimelineLite();
            DisplayUtil.removeMe(this._spExpandContainer);
            this._tween.append(TweenLite.to(this._spFunc, 0.2, {x:0}));
            this._isExpanding = true;
            CopyInfo_TaskTrackConnector.updateLaout(true);
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            CopyInfo_TaskTrackConnector.updateLaout(true);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._spFunc.dispose(param1);
            this._spFunc = null;
            this._bodySprite.dispose(param1);
            this._bodySprite = null;
            this._moveBtn.dispose(param1);
            this._moveBtn = null;
            this._btnUnExpand.dispose(param1);
            this._btnUnExpand = null;
            this._spExpandContainer.dispose(param1);
            this._spExpandContainer = null;
            this._btnExpandBg.dispose(param1);
            this._btnExpandBg = null;
            this._btnExpand.dispose(param1);
            this._btnExpand = null;
            this._bmpCopyLabel.dispose(param1);
            this._bmpCopyLabel = null;
            if (this._tween != null)
            {
                this._tween.kill();
                this._tween = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        protected function onMoveBtnMouseHandler(event:MouseEvent) : void
        {
            startDrag(false, this._dragRect);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        protected function onStageMouseUpHandler(event:MouseEvent) : void
        {
            stopDrag();
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

    }
}
